package cn.com.css.taxInspection.attention.service.impl;

import cn.com.css.taxInspection.attention.entity.JcAjglSdaylxzdEntity;
import cn.com.css.taxInspection.attention.mapper.JcAjglSdaylxzdMapper;
import cn.com.css.taxInspection.attention.service.JcAjglSdaylxzdService;
import cn.com.css.taxInspection.util.TsBqUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@Service("JcAjglSdaylxzdService")
public class JcAjglSdaylxzdServiceImpl extends ServiceImpl<JcAjglSdaylxzdMapper, JcAjglSdaylxzdEntity> implements JcAjglSdaylxzdService {

    @Override
    @DS("oracle")
    public IPage<JcAjglSdaylxzdEntity> getSdaylxzdPage(JcAjglSdaylxzdEntity jcAjglSdaylxzdEntity) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        IPage<JcAjglSdaylxzdEntity> page = new Page<>(jcAjglSdaylxzdEntity.getPage(), jcAjglSdaylxzdEntity.getLimit());
        LambdaQueryWrapper<JcAjglSdaylxzdEntity> queryWrapper = Wrappers.lambdaQuery();
        //字典名称
        if (TsBqUtils.isNotNull(jcAjglSdaylxzdEntity.getZdmc())) {
            queryWrapper.eq(JcAjglSdaylxzdEntity::getZdmc, jcAjglSdaylxzdEntity.getZdmc());
        }
        //立案开始时间
        if (!StringUtils.isEmpty(jcAjglSdaylxzdEntity.getZdstartTime())) {
            queryWrapper.ge(JcAjglSdaylxzdEntity::getCjsj, sdf.parse(jcAjglSdaylxzdEntity.getZdstartTime()));
            queryWrapper.le(JcAjglSdaylxzdEntity::getCjsj, sdf.parse(jcAjglSdaylxzdEntity.getZdendTime()));
        }
        queryWrapper.orderByAsc(JcAjglSdaylxzdEntity::getCjsj);
        return this.page(page, queryWrapper);
    }
}
